package com.wxmp.market.zhuli.service;


import com.wxmp.wxapi.vo.MsgRequest;
import com.wxmp.wxcms.domain.MsgLog;
import com.wxmp.wxcms.mapper.MsgLogDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Service("msgLogProcessor")
public class MsgLogProcessor {

    private ExecutorService executor = Executors.newCachedThreadPool();

    @Resource
    private MsgLogDao logDao;

    public void logWrite(MsgRequest msgRequest) {
        executor.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    MsgLog msgLog = new MsgLog();
                    msgLog.setToOpenid(msgRequest.getToUserName());
                    msgLog.setFromOpenid(msgRequest.getFromUserName());
                    msgLog.setMsgType(msgRequest.getMsgType());
                    msgLog.setEventType(msgRequest.getEvent());
                    msgLog.setEventKey(msgRequest.getEventKey());
                    msgLog.setMsgContent(msgRequest.getContent());
                    logDao.add(msgLog);
                } catch (Exception e) {
                    throw new RuntimeException("报错啦！！");
                }
            }
        });
    }
}
